<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="copyright" content="www.infoearth.com" />
    <title>侧边导航</title>
    <link rel="stylesheet" href="lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="lib/jquery.mobile-1.4.5/jquery.min.js"></script>
    <script src="lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <script src="lib/config.js"></script>
    <script src="lib/common.js"></script>
    <style>
    html {
        height: 100%;
        background-color: #fff;
    }

    body {
        background-color: #fff;
        padding: 0;
        margin: 0;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        height: 100%;
        -webkit-box-orient: vertical;
        -webkit-flex-flow: column;
        flex-flow: column;
    }
    </style>
</head>

<body>
    <div>
        <div style="height:100px;margin-top:30px;">
            <img src="image/logo.png" />
        </div>
        <div style="margin: 10px 10px;">
            <label for="tbUserName">用户名：</label>
            <input id="tbUserName" type="tel" value="" data-clear-btn="true">
            <label for="tbPwd">密码：</label>
            <input id="tbPwd" type="Password" value="" data-clear-btn="true">
        </div>
        <div style="margin: 20px 10px;">
            <input type="button" value="登录" id="btnLogin">
        </div>
        <div style="margin: 20px 10px;">
            <label>
                <input type="checkbox" id="chkSavePwd" checked=""> 记住密码 </label>
        </div>
    </div>
</body>
<script type="text/javascript" src="script/api.js"></script>
<script type="text/javascript">
apiready = function() {
    //获取用户信息（记住用户名的情况)
    var userInfo = getCookie('userInfo');
    if (userInfo != null && userInfo != '') {
        var strList = userInfo.split('#');
        $("#tbUserName").val(strList[0]);
        if (strList[1] != '') {
            $("#tbPwd").val(strList[1]);
            $("#chkSavePwd").attr("checked", true);
        } else
            $("#chkSavePwd").attr("checked", false);
    }
    $("#btnLogin").click(function() {
        var userName = $("#tbUserName").val();
        var pwd = $("#tbPwd").val();
        var savePwd = $('#chkSavePwd').is(':checked');
        if (userName == '' || pwd == '') {
            showMsg("请输入用户名密码！");
            return;
        }
        getNameByPhone(pwd);
        //				var state = Login(userName, pwd);
        var state = true;
        //test
        if (state == false) {
            showMsg("用户名密码有误！");
            return;
        }
        if (savePwd == true) {
            setCookie('userInfo', userName + "#" + pwd);
        } else {
            setCookie('userInfo', userName + "#" + '');
        }
        api.openWin({
            name: 'main',
            url: 'html/main.html'
        });
    });
}

function getNameByPhone(pwd) {
    $.ajax({
        url: ip_req + 'ZHFZ/ZHFZService.svc/GetQCQFManByPhone',
        type: 'GET',
        dataType: 'jsonp',
        data: {
            phone: pwd,
        }
    }).done(function(res) {
//         showMsg("QcqfMan" + res.QCQFManName+'ddd  '+pwd);
        setCookie('QcqfMan', res.QCQFManName);
        setCookie('PhoneNum', pwd);
    });
}

function Login(phoneNum, pwd) {
    api.showProgress({
        style: 'default',
        animationType: 'fade',
        title: '正在登录中',
        text: '请稍等...',
        modal: false
    });
    //自动登录df平台，生成token
    autoLoginUser();
    //验证用户是否是群测群防员
    var state = false;
    var filter = "QCQFDSH02070='B' and QCQFD01090='" + phoneNum + "'";
    getRecordsByFilter("qcqf", "vwQCQFD", filter, function(response) {
        if (response != null && response.record != null && response.record.length > 0) {
            //群测群防员的姓名
            setCookie('QcqfMan', response.record[0].QCQFD01080);
            setCookie('PhoneNum', phoneNum);
            state = true;
        }
    }, showErro, false);
    //密码固定为123456，用户名即群测群防员的手机号
    if (pwd != '123456')
        state = false;
    api.hideProgress();
    return state;
}
</script>

</html>
